package whu.cn.whushare.ui.main.activity;

import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.RadioGroup;
import android.widget.TextView;

import com.androidplus.util.StringUtil;
import com.androidplus.util.ViewMapping;
import com.androidplus.util.ViewMappingUtil;

import whu.cn.whushare.R;
import whu.cn.whushare.bean.Result;
import whu.cn.whushare.bean.User;
import whu.cn.whushare.common.UserManager;
import whu.cn.whushare.net.DownloadParams;
import whu.cn.whushare.net.Downloader;
import whu.cn.whushare.ui.common.BaseActivity;
import whu.cn.whushare.ui.main.MainTabActivity;
import whu.cn.whushare.ui.main.activity.bean.Activity;
import whu.cn.whushare.ui.main.my.LoginActivity;

/**
 * Created by xiaoping on 2015/3/30.
 */
@ViewMapping(id = R.layout.activity_launch_activity)
public class ActivityLaunchActivity extends BaseActivity implements View.OnClickListener{
    @ViewMapping(id = R.id.edit_activity_name)
    private EditText mActivityName;
    @ViewMapping(id = R.id.edit_end_time)
    private EditText mEndTime;
    @ViewMapping(id = R.id.edit_show_time)
    private EditText mShowTime;
    @ViewMapping(id = R.id.edit_activity_place)
    private EditText mActivityPlace;
    @ViewMapping(id = R.id.edit_activity_host)
    private EditText mActivityHost;
    @ViewMapping(id = R.id.edit_host_contact)
    private EditText mHostContact;
    @ViewMapping(id = R.id.edit_activity_content)
    private EditText mActivityContent;
    private UserManager mUserManager;
    private Activity mActivity;

    public static Intent getStartIntent(Context context) {
        Intent i = new Intent(context, ActivityLaunchActivity.class);
        return i;
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        mUserManager = UserManager.getInstance(this);
        initViewsAndActions();
    }

    private void initViewsAndActions() {
        View root = ViewMappingUtil.mapView(this, this);
        getTopBar(root);
        mTopBar.title.setText(R.string.launch_activity);
        mTopBar.searchView.setVisibility(View.INVISIBLE);
        mTopBar.rightImg.setVisibility(View.INVISIBLE);
        mTopBar.rightText.setVisibility(View.VISIBLE);
        mTopBar.rightText.setText(R.string.launch);
        initLaunchAction();
    }


    private void initLaunchAction() {
        mTopBar.rightText.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Activity activity = new Activity();
                activity.setActivityName(mActivityName.getText().toString());
                activity.setActivityDetail(mActivityContent.getText().toString());
                activity.setAddress(mActivityPlace.getText().toString());
                activity.setEndTime(mEndTime.getText().toString());
                activity.setHostTime(mShowTime.getText().toString());
                activity.setHostPeople(mActivityHost.getText().toString());
                activity.setPhoneNum(mHostContact.getText().toString());
                String activityName = mActivityName.getText().toString();
                String activityDetail = mActivityContent.getText().toString();
                String address = mActivityPlace.getText().toString();
                String endTime = mEndTime.getText().toString();
                String hostTime = mShowTime.getText().toString();
                Downloader.getInstance(ActivityLaunchActivity.this).launchActivity(activityName, activityDetail, endTime, hostTime, address, ActivityLaunchActivity.this);
             }
        });
    }

    @Override
    public <T> void onSuccess(DownloadParams.PARSING_TYPE type, Result<T> response, Object obj) {
        super.onSuccess(type, response, obj);

        switch (type) {
            case LAUNCH_ACTIVITY:
                toast("成功发起活动!");

                break;

            default:
                break;

        }

    }


}
